//
//  FeedbackController.m
//  HarmonizePub
//
//  Created by rzhy on 2016/11/15.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "FeedbackController.h"
#import "Config.h"
#import "User.h"
#import "Utils.h"

@interface FeedbackController () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *sendButton;

@end

@implementation FeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.textView.layer.cornerRadius = 5.0f;
    self.textView.layer.masksToBounds = YES;
    self.textView.layer.borderWidth = 0.5f;
    self.textView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.sendButton.layer.cornerRadius = 5.0f;
    self.sendButton.layer.masksToBounds = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 提交
- (IBAction)sendEvent:(UIButton *)sender {
    NSString *text = self.textView.text;
    if (!text || [text isEqualToString:@""])
        [self setAlertViewWithMessage:@"请输入问题反馈！"];
    else {
        NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
        NSDictionary *param = @{@"type" : @"2", @"content" : text};
        [HTTPSTool POSTRequestWithPath:XHUserAddSuggest cookie:cookie params:param success:^(NSDictionary * _Nonnull JSON) {
//            XHLog(@"问题反馈 -> JSON: %@", JSON);
            [ZYToast showBottomText:@"提交成功！"];
            self.textView.text = nil;
            [self.navigationController popViewControllerAnimated:YES];
        }];
    }
}

#pragma mark - alert view
- (void)setAlertViewWithMessage:(NSString *)message {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提 示:" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:defaultAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:NO];
}

@end
